package start.aai.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import start.aai.common.Ollama.OllamaClient;
import start.aai.entity.Conversations;
import start.aai.entity.DTO.MessageDTO;
import start.aai.service.ConversationsService;
import start.aai.common.Result;

import java.net.Inet4Address;
import java.util.List;

@RestController
@RequestMapping("/ai/conversations")
@Slf4j
public class ConversationController {
    @Resource
    private ConversationsService conversationsService;

    @PostMapping("/newConversation")
    public Result newConversation(@RequestBody Conversations conversations) {
        Integer tag = conversationsService.newConversation(conversations);
        log.info("当前对话id为:{}", conversations.getId());
        MessageDTO.conversationid=conversations.getId();
        return tag==1  ? Result.success() : Result.error("新建会话失败");
    }

    @PostMapping("/clearHistory")
    public Result clearHistory() {
        OllamaClient.clearHistory();
        return Result.success();
    }

    @GetMapping("/getHistory")
    public Result getHistory(@RequestParam Integer userId) {
        List<Conversations> list= conversationsService.getHistory(userId);
        return Result.success(list);
    }

}
